/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

/**
 * <p>Project: javase2203 - MessageEnum
 * <p>Powered by webrx On 2022-08-10 16:31:37
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public enum MessageEnum {
    SAVE(100, "保存"),
    OPEN(800, "打开"),
    ERROR(400, "错误"),
    MESSAGE(200, "成功"),
    INFO(202, "信息提示"),
    DEBUG(404, "调试");

    private int code;
    private String msg;

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    MessageEnum(int code, String msg) {
        System.out.println(this);
        this.code = code;
        this.msg = msg;
    }

    public static MessageEnum fromTypeCode(int code) {
        if(code>=1000){
            return ERROR;
        }
        for (MessageEnum type : MessageEnum.values()) {
            if (type.code == code) {
                return type;
            }
        }
        return null;
    }

    public static MessageEnum fromTypeMsg(String msg) {
        for (MessageEnum type : MessageEnum.values()) {
            if (type.msg.equals(msg)) {
                return type;
            }
        }
        return null;
    }
}
